﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Text;
using System.Text.RegularExpressions;

namespace Cemit.PolyServer
{
    /// <summary>
    /// 管理数据库连接
    /// </summary>
    [Obsolete("暂停开发")]
    static class DbManager
    {
        const string CONNECT_STR
            = @"Data Source=CEMIT-LANQ\SQLEXPRESS;Initial Catalog=PolyServer_0_1_2;Integrated Security=True";

        static DbConnection db;

        public static bool Connect()
        {
            try
            {
                db = new SqlConnection(CONNECT_STR);
                db.Open();
            }
            catch (Exception e)
            {
                Debug.LogError("无法连接到数据库：" + e.Message);
                return false;
            }
            return true;
        }

        private static bool IsSafeString(string str)
        {
            return !Regex.IsMatch(str, @"[-|;|,|\/|\(|\)|\[|\]|\{|\}|%|@\*|!|\']");
        }

        /// <summary>
        /// 是否存在该用户
        /// </summary>
        public static bool IsAccountExist(string id)
        {
            if (!IsSafeString(id))
            {
                return false;
            }
            return false;
        }
    }
}
